package si.yun.config.properties;

import com.github.wxpay.sdk.WXPayConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import java.io.InputStream;

@Component
@PropertySource("classpath:/config/wechatpay.properties")
public class WechatPayProperties implements WXPayConfig {
	/**
	 * appID
	 */
	@Value("${pay.wxpay.app.appID}")
	private String appID;

	/**
	 * 商户号
	 */
	@Value("${pay.wxpay.app.mchID}")
	private String mchID;

	/**
	 * API 密钥
	 */
	@Value("${pay.wxpay.app.key}")
	private String key;

	/**
	 * API证书绝对路径 (本项目放在了 resources/config/apiclient_cert.p12")
	 */
	@Value("${pay.wxpay.app.certPath}")
	private String certPath;

	/**
	 * HTTP(S) 连接超时时间，单位毫秒
	 */
	private int httpConnectTimeoutMs = 8000;

	/**
	 * HTTP(S) 读数据超时时间，单位毫秒
	 */
	private int httpReadTimeoutMs = 10000;

	/**
	 * 微信支付异步通知地址
	 */
	@Value("${pay.wxpay.app.payNotifyUrl}")
	private String payNotifyUrl;

	/**
	 * 微信退款异步通知地址
	 */
	@Value("${pay.wxpay.app.payNotifyUrl}")
	private String refundNotifyUrl;

	/**
	 * 获取商户证书内容（这里证书需要到微信商户平台进行下载）
	 *
	 * @return 商户证书内容
	 */
	@Override
	public InputStream getCertStream() {
		InputStream certStream  =getClass().getClassLoader().getResourceAsStream(certPath);
		return certStream;
	}

	public String getAppID() {
		return appID;
	}

	public void setAppID(String appID) {
		this.appID = appID;
	}

	public String getMchID() {
		return mchID;
	}

	public void setMchID(String mchID) {
		this.mchID = mchID;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getCertPath() {
		return certPath;
	}

	public void setCertPath(String certPath) {
		this.certPath = certPath;
	}

	public int getHttpConnectTimeoutMs() {
		return httpConnectTimeoutMs;
	}

	public void setHttpConnectTimeoutMs(int httpConnectTimeoutMs) {
		this.httpConnectTimeoutMs = httpConnectTimeoutMs;
	}

	public int getHttpReadTimeoutMs() {
		return httpReadTimeoutMs;
	}

	public void setHttpReadTimeoutMs(int httpReadTimeoutMs) {
		this.httpReadTimeoutMs = httpReadTimeoutMs;
	}

	public String getPayNotifyUrl() {
		return payNotifyUrl;
	}

	public void setPayNotifyUrl(String payNotifyUrl) {
		this.payNotifyUrl = payNotifyUrl;
	}

	public String getRefundNotifyUrl() {
		return refundNotifyUrl;
	}

	public void setRefundNotifyUrl(String refundNotifyUrl) {
		this.refundNotifyUrl = refundNotifyUrl;
	}

}
